package com.r2coding.article.controller;

import com.r2coding.article.vo.req.CommentReqVo;
import com.r2coding.article.vo.resp.MessageRespVo;
import org.springframework.beans.factory.annotation.Autowired;

import com.r2coding.article.entity.MessageEntity;
import com.r2coding.article.service.MessageService;
import com.r2coding.common.util.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 留言
 *
 * @author 98k灬
 * @email hk666zx@163.com
 * @date 2022-06-04 00:37:57
 */
@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    /**
     * 保存
     */
    @PostMapping("/save")
    public Result save(@RequestBody MessageEntity message){
		messageService.save(message);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result update(@RequestBody MessageEntity message){
		messageService.updateById(message);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PreAuthorize("hasAuthority('message:delete')")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id){
		messageService.removeById(id);
        return Result.ok();
    }

    /**
     * 分页查询留言信息列表
     *
     * @param req 请求信息
     * @return 统一响应体
     */
    @PostMapping("/list")
    public Result list(@RequestBody CommentReqVo req) {
        MessageRespVo resp = messageService.listMessage(req);
        return Result.ok(resp);
    }
}
